//
//  ToBeSureTaskItemDetailVC.m
//  MyProject
//
//  Created by Pei on 16/7/14.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "ToBeSureTaskItemDetailVC.h"
#import "IHRefreshTableView.h"
#import "WriteCheckItemDetailViewController.h"
#import "UIImageView+WebCache.h"
#import "JZAlbumViewController.h"

@interface ToBeSureTaskItemDetailVC ()
{
    UIScrollView *_mainScrollView;
    
    
    UILabel *_lbl0;
    UILabel *_lbl1;
    UILabel *_lbl2;
    UILabel *_lbl3;
    
    UITextView *_inputField;
    
    UIView *_inputView;
    
    NSDictionary *_currentDic;
    
    NSArray *imageUrlList;
}

@end

@implementation ToBeSureTaskItemDetailVC

- (id)initWithDic:(NSDictionary*)dic
{
    self = [super init];
    if (self) {
        _currentDic = dic;
    }
    return self;
}

- (void)viewDidLoad {
    self.navTitle = @"检查任务详情";
    [super viewDidLoad];
    
    
    
    _mainScrollView = [[UIScrollView alloc] init];
    _mainScrollView.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, kDeviceHeight-NAV_HEIGHT);
    _mainScrollView.backgroundColor = kWhiteColor;
    _mainScrollView.contentSize = CGSizeMake(kDeviceWidth, kDeviceHeight-NAV_HEIGHT+10.0f);
    [self.view addSubview:_mainScrollView];
    
    
    _lbl0 = [[UILabel alloc] init];
    _lbl0.frame = CGRectMake(10.0, (40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth-10.0f*2.0f, Home_Small_Size+2.0f);
    _lbl0.font = kAppFont(Home_Small_Size+2.0f);
    _lbl0.textColor = kBlackColor;
    NSArray *arrayT = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
    if (arrayT != nil && arrayT.count > 0) {
        for (NSDictionary *dddd in arrayT) {
            if ([[dddd valueForKey:@"Value"] intValue] == [[_currentDic valueForKey:@"RiskLevel"] intValue]) {
                _lbl0.text = [NSString stringWithFormat:@"隐患级别：%@", [dddd valueForKey:@"Name"]];
            }
        }
    }else{
        [self getLevelData];
    }
    
    [_mainScrollView addSubview:_lbl0];
    
    UIView *lineView0 = [[UIView alloc] init];
    lineView0.frame = CGRectMake(0.0f, 40.0f-0.5f, kDeviceWidth, 0.5f);
    lineView0.backgroundColor = kGreenColor;
    [_mainScrollView addSubview:lineView0];
    
    
    _lbl1 = [[UILabel alloc] init];
    _lbl1.frame = CGRectMake(10.0, lineView0.bottom+(40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth/2.0f-10.0f*2.0f-5.0f, Home_Small_Size+2.0f);
    _lbl1.font = kAppFont(Home_Small_Size+2.0f);
    _lbl1.textColor = kBlackColor;
    _lbl1.text = [NSString stringWithFormat:@"总分：%d", [[_currentDic valueForKey:@"RiskTotalPoints"] intValue]];
    [_mainScrollView addSubview:_lbl1];
    
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.frame = CGRectMake(kDeviceWidth/2.0f, lineView0.bottom, 0.5f, 40-0.5f);
    lineView1.backgroundColor = kGreenColor;
    [_mainScrollView addSubview:lineView1];
    
    
    
    _lbl2 = [[UILabel alloc] init];
    _lbl2.frame = CGRectMake(lineView1.right+ 10.0, lineView0.bottom+(40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth/2.0f-10.0f*2.0f-5.0f, Home_Small_Size+2.0f);
    _lbl2.font = kAppFont(Home_Small_Size+2.0f);
    _lbl2.textColor = kBlackColor;
    _lbl2.text = [NSString stringWithFormat:@"扣分：%d", [[_currentDic valueForKey:@"RiskPoints"] intValue]];
    [_mainScrollView addSubview:_lbl2];
    
    UIView *lineView2 = [[UIView alloc] init];
    lineView2.frame = CGRectMake(0.0f, 80.0f-0.5f, kDeviceWidth, 0.5f);
    lineView2.backgroundColor = kGreenColor;
    [_mainScrollView addSubview:lineView2];
    
    _lbl3 = [[UILabel alloc] init];
    _lbl3.frame = CGRectMake(10.0, lineView2.bottom+(40-(Home_Small_Size+2.0f))/2.0f, kDeviceWidth-10.0f*2.0f, Home_Small_Size+2.0f);
    _lbl3.font = kAppFont(Home_Small_Size+2.0f);
    _lbl3.textColor = kBlackColor;
    _lbl3.text = [NSString stringWithFormat:@"检查内容：%@", [_currentDic valueForKey:@"RiskName"]];
    [_mainScrollView addSubview:_lbl3];
    
    UIView *lineView3 = [[UIView alloc] init];
    lineView3.frame = CGRectMake(0.0f, 120.0f-0.5f, kDeviceWidth, 0.5f);
    lineView3.backgroundColor = kGreenColor;
    [_mainScrollView addSubview:lineView3];


    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.frame = CGRectMake(10.0, lineView3.bottom+ 10.0f, 60.0f, Home_Small_Size+2.0f);
    titleLbl.font = kAppFont(Home_Small_Size+2.0f);
    titleLbl.textColor = kBlackColor;
    titleLbl.text = @"描述";
    [_mainScrollView addSubview:titleLbl];
    
    UILabel *inputLbl = [[UILabel alloc] init];
    inputLbl.frame = CGRectMake(10.0, titleLbl.bottom+10.0f, kDeviceWidth-10*2, Home_Small_Size+2.0f);
    inputLbl.font = kAppFont(Home_Small_Size+2.0f);
    inputLbl.textColor = kBlackColor;
    inputLbl.text = [_currentDic valueForKey:@"RiskDesc"];
    [inputLbl setNumberOfLines:0];
    inputLbl.height = [inputLbl.text boundingRectWithSize:CGSizeMake(inputLbl.width, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:inputLbl.font} context:nil].size.height;
    [_mainScrollView addSubview:inputLbl];
    
    
    UIView *lineView4 = [[UIView alloc] init];
    lineView4.frame = CGRectMake(0.0f, inputLbl.bottom+20.0f, kDeviceWidth, 0.5f);
    lineView4.backgroundColor = kGreenColor;
    [_inputView addSubview:lineView4];
    
    
    //四列
    int totalloc = 4;
    CGFloat tempWidth = (kDeviceWidth-10.0f*5.0f)/4.0f;
    CGFloat tempHeight = (kDeviceWidth-10.0f*5.0f)/4.0f;
    
    int margin = 10;
    
    NSArray *imageArray = [_currentDic valueForKey:@"RiskAttchUrlList"];
    
    imageUrlList = imageArray;
    
    for (int i = 0; i < imageArray.count; i ++) {
        
        int row=i/totalloc;//行号
        //1/3=0,2/3=0,3/3=1;
        int loc=i%totalloc;//列号
        
        CGFloat appviewx = margin+(margin+tempWidth)*loc;
        CGFloat appviewy = margin+(margin+tempHeight)*row;
        
        
        UIImageView *tempImageView = [[UIImageView alloc] init];
        
        tempImageView.userInteractionEnabled=YES;
        tempImageView.tag = i;
        UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage:)];
        [tempImageView addGestureRecognizer:singleTap];
        
        tempImageView.frame = CGRectMake(appviewx, lineView4.bottom+appviewy, tempWidth, tempHeight);
        [tempImageView sd_setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"normalDefault"]];
        [_mainScrollView addSubview:tempImageView];
        
        
    }
    
}

- (void)onClickImage:(UITapGestureRecognizer*)sender{
    JZAlbumViewController *jzAlbumVC = [[JZAlbumViewController alloc] init];
    
    jzAlbumVC.currentIndex = sender.view.tag;//这个参数表示当前图片的index，默认是0
    
    jzAlbumVC.imgArr = [[NSMutableArray alloc] initWithArray:imageUrlList];//图片数组，可以是url，也可以是UIImage
    [self.navigationController pushViewController:jzAlbumVC animated:YES];
}



- (void)getLevelData{
    [[YMNetLib getInstance] connectWithAction:Dictionary_Type_API method:@"GET" withContent:@"DicType=RiskLevel" withBody:nil withDelegate:self];
}

- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([[YMNetDataUtil getSuccessState:body] intValue] == 1){
        [[NSUserDefaults standardUserDefaults] setObject:[body valueForKey:@"DicList"] forKey:select_RiskLevel];
        NSArray *arrayT = [[NSUserDefaults standardUserDefaults] objectForKey:select_RiskLevel];
        if (arrayT != nil && arrayT.count > 0) {
            for (NSDictionary *dddd in arrayT) {
                if ([[dddd valueForKey:@"Value"] intValue] == [[_currentDic valueForKey:@"RiskLevel"] intValue]) {
                    _lbl0.text = [NSString stringWithFormat:@"隐患级别：%@", [dddd valueForKey:@"Name"]];
                }
            }
        }
    }
        
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
